package com.ysd.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ysd.entity.Cart;
import com.ysd.service.CartService;
import com.ysd.util.Result;

@Controller
public class CartController {
	@Autowired
	private CartService cartService;

	@RequestMapping("getAll")
	@ResponseBody
	public Object getAll(int uid) {
		List<Cart> list = cartService.getAll(uid);
		return list;
	}

	@RequestMapping("updateCart")
	@ResponseBody
	public String updateCart(int id, int num) {
		int n = cartService.updateCart(id, num);
		if (n > 0) {
			return Result.toClient("0", "修改成功", null);
		} else {
			return Result.toClient("1", "修改失败", null);
		}
	}

	@RequestMapping("deleteCartByWhere")
	@ResponseBody
	public Object deleteCartByWhere(int id) {
		int n = cartService.deleteCart(id);
		if (n > 0) {
			return Result.toClient("0", "删除成功", null);
		} else {
			return Result.toClient("1", "删除失败", null);
		}
	}

	@RequestMapping("deleteCartByUid")
	@ResponseBody
	public Object deleteCartByUid(int uid) {
		int x = cartService.deleteCarts(uid);
		if (x > 0) {
			return Result.toClient("0", "删除成功", null);
		} else {
			return Result.toClient("1", "删除失败", null);
		}
	}
}